factorial <- function(n)
{
    fact <- 1
    for(i in n:1 )
        fact <- fact * i
    fact
}